package com.chexiehui.jc.mvp.car;

import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.StringUtils;
import com.chexiehui.jc.AppApplication;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;

/**
 * @Description 特价车询价
 * @Auth SongJun
 * @Date 2020/05/21 00:18
 **/
public class SpecialCarInquiryPresenter extends BasePresenter<SpecialCarInquiryCovenant.View, SpecialCarInquiryCovenant.Stores>
        implements SpecialCarInquiryCovenant.Presenter {

    public SpecialCarInquiryPresenter(SpecialCarInquiryCovenant.View view) {
        attachView(view);
    }

    @Override
    public void addShopInquiry() {
        if(StringUtils.isTrimEmpty(mvpView.getCarId()) || StringUtils.isTrimEmpty(mvpView.getShopId())){
            mvpView.showToast("参数错误");
            return;
        }
        if(StringUtils.isTrimEmpty(mvpView.getPersonPhone())){
            mvpView.showToast("请输入手机号");
            return;
        }
        if(!RegexUtils.isMobileSimple(mvpView.getPersonPhone())){
            mvpView.showToast("请输入正确手机号");
            return;
        }
        if(StringUtils.isTrimEmpty(mvpView.getPersonName())){
            mvpView.showToast("请输入姓名");
            return;
        }
        mvpView.showLoading("正在提交");
        addSubscription(appStores.addShopInquiry("2", mvpView.getCarId(), mvpView.getShopId(),
                mvpView.getPersonPhone(), mvpView.getPersonName(), AppApplication.getInstances().getPubCity()),
                new ApiCallback<BaseModel<Object>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<Object> model) {
                        if (model.getResultCode() == 0) {
                            mvpView.hide();
                            mvpView.onAddShopInquirySuccess(model);
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.hide();
                        mvpView.onAddShopInquiryFailure(new BaseModel<>(code, msg));
                    }
                });
    }

}